{extend name="admin@index_layout"/}
{block name="main"}
<style>
    .layui-form-label {
        width: 150px;
    }

    .layui-form-item .layui-input-inline {
        width: 520px;
    }
</style>
<div class="layui-card">
    {notempty name="$success_url"}
    {empty name="$no_title"}
    <div class="layui-card-header">新增/编辑</div>
    {/empty}
    {/notempty}
    <div class="layui-card-body">
        <form class="layui-form form-horizontal" method="post">
            <input type="hidden" name="id" value="{$id|default=0}">
            <input type="hidden" name="action" value="{$action|default=1}">
            <input type="hidden" name="model" value="{$model|default=''}">
            <input type="hidden" name="is_verify" value="{$is_verify|default=1}">
            <input type="hidden" name="module" value="{$module|default=''}">
            <input type="hidden" name="is_scene" value="{$is_scene|default=0}">
            <input type="hidden" id="url" value="{$url}">
            <input type="hidden" id="success_url" name="success" value="{$success_url}">
            {include file="admin@common/formItem" /}
            {if count($formList)}
            <div class="layui-form-item">
                <div class="layui-input-block">
                    {notempty name="$success_url"}
                    <button class="layui-btn ajax-post" lay-submit="" lay-filter="formSubmit"
                            target-form="form-horizontal">立即提交
                    </button>
                    {empty name="$no_return"}
                    <button class="layui-btn layui-btn-normal" type="button" onclick="javascript:history.back(-1);">返回
                    </button>
                    {/empty}
                    {/notempty}
                </div>
            </div>
            {/if}
        </form>
    </div>
</div>
{/block}
{block name="layui"}{/block}
{block name="script"}
<script type="text/javascript">
    layui.config({
        base: '__STATIC__/libs/',
        version: 'v1'
    }).extend({
        croppers: "cropper/croppers",
        // ckplayer: 'ckplayer/ckplayer'
    });
    layui.use(['form', 'layer'], function () {
        var form = layui.form, layer = layui.layer, target;
        // var layarea = layui.layarea;
        // layarea.render({
        //     elem: '#area-picker',
        //     change: function (res) {
        //         //选择结果
        //         // console.log(res);
        //     }
        // });

        //点击全选, 勾选
        form.on('checkbox(allChoose)', function (data) {
            var child = $(this).parent().parent().find(".layui-input-inline input[type='checkbox']");
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });


        form.on('submit(formSubmit)', function (e) {
            var index = layer.load(1);
            target = $('.form-horizontal').attr("action");
            var url = $('#url').val();
            $.post(url, $('.form-horizontal').serialize()).success(function (res) {
                if (res.code === 0) {
                    if  (res && res.data && res.data.close === 1) {
                        layer.msg(res.msg, {time: 1000}, function () {
                            parent.closeAllLayers(true)
                        });
                    } else {
                        var success_url = $('#success_url').val();
                        layer.msg(res.msg, {time: 1000}, function () {
                            location.href = success_url;
                        });
                    }
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
                layer.close(index);
            });
            return false;
        });

    })
</script>
<script>
    function jump(url) {
        location.href = url;
    }
</script>

<!-- 设置额外的html代码 -->
{if $extra_html}
{$extra_html|raw}
{/if}

{/block}
